package com.qiniuyun.pictransmission.controller;


import com.qiniuyun.pictransmission.service.DownloadService;
import com.qiniuyun.pictransmission.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/download")
@Api(value = "下载文件",tags = "下载文件")

public class Download {


    @Autowired
    private DownloadService downloadService;

    @ApiOperation("图片文件下载")
    @GetMapping("/downloadPic")
    public Result downloadPic(@RequestParam(value = "picName") String picName) {
        String url = downloadService.download(picName);
        if("下载失败".equals(url)){
            return Result.error("下载失败！请检查所选图片名称是否有误。");
        }else {
            return Result.ok("下载成功！url为：" + url);
        }
    }
}
